package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.InHospital;
import com.woniuxy.entity.dto.InHospitalDTO;
import com.woniuxy.mapper.AdmissionFormMapper;
import com.woniuxy.mapper.InHospitalMapper;
import com.woniuxy.mapper.SickBedMapper;
import com.woniuxy.service.InHospitalService;
import com.woniuxy.service.SaasService;
import com.woniuxy.util.PageParam;
import com.woniuxy.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class InHospitalServiceImpl implements InHospitalService, SaasService {
    @Autowired
    InHospitalMapper inHospitalMapper;
    @Autowired
    AdmissionFormMapper admissionFormMapper;
    @Autowired
    SickBedMapper sickBedMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseData<?> addHz(InHospitalDTO inHospitalDTO) {
        inHospitalDTO.setStatus(2);
        admissionFormMapper.updateAdStatus(inHospitalDTO);
        inHospitalDTO.setStatus(1);
        sickBedMapper.updateSbStatus(inHospitalDTO);
        Integer i = inHospitalMapper.addHz(inHospitalDTO);
        System.out.println(i);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> queryInHospitals(PageParam<InHospitalDTO> pageParam) {
        PageHelper.startPage(pageParam.getPageNum(),pageParam.getPageSize());
        InHospitalDTO param = pageParam.getParam();
        List<InHospital> inHospitals = inHospitalMapper.queryInHospitals(param);
        PageInfo<InHospital> pageInfo = new PageInfo<>(inHospitals);
        return new ResponseData<>().ok(pageInfo);
    }
}
